<template>

  <div>
    <el-alert style="background-color: #409EFF; color: #222222; font-style: unset; margin-top: 10px; margin-bottom: 20px" :closable="false" title="日志管理" />
    <el-form :inline="true" size="small" style="margin-left: 15px" :model="searchForm" class="demo-form-inline">
      <el-form-item label="操作类型">
        <el-select v-model="searchForm.operationType" placeholder="请选择" clearable>
          <el-option label="登录" value="login"></el-option>
          <el-option label="登出" value="logout"></el-option>
          <el-option label="新增" value="insert"></el-option>
          <el-option label="删除" value="delete"></el-option>
          <el-option label="修改" value="update"></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="用户名">-->
<!--        <el-input-->
<!--          v-model="searchForm.username"-->
<!--          placeholder="用户名"-->
<!--          clearable-->
<!--        ></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户名">-->
<!--        <el-input-->
<!--          v-model="searchForm.username"-->
<!--          placeholder="用户名"-->
<!--          clearable-->
<!--        ></el-input>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button icon="el-icon-search" @click="load">搜索</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button icon="el-icon-plus" type="primary" @click="dialogVisible = true" >新增</el-button>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <template>-->
<!--          <el-popconfirm-->
<!--            title="确定要批量删除吗？"-->
<!--            @confirm="deleteRole(null)"-->
<!--          >-->
<!--            <el-button :disabled="delBtlStatus" icon="el-icon-delete" slot="reference" type="danger">批量删除</el-button>-->
<!--          </el-popconfirm>-->
<!--        </template>-->
<!--      </el-form-item>-->
    </el-form>
    <el-divider></el-divider>
    <!--    <div class="table">-->
    <el-table class="content" tooltip-effect="dark"
              border :data="tableData.slice((currentPage-1)*PageSize,currentPage*PageSize)"
              :header-cell-style="{'text-align':'center'}">
      <el-table-column prop="ip" label="访问IP" align="center">
      </el-table-column>
      <el-table-column prop="url" label="url" />
      <el-table-column prop="requestMethod" label="请求方式" align="center"/>
      <el-table-column prop="primaryKey" label="主键" />
      <el-table-column prop="operationType" label="操作类型" align="center">
<!--        <template slot-scope="scope">-->
<!--          <el-tag v-if="scope.row.statu == '0'" size="small" type="danger">禁用</el-tag>-->
<!--          <el-tag v-if="scope.row.statu == '1'" size="small" type="success">启用</el-tag>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column prop="entity" label="操作实体" />
      <el-table-column prop="requestData" label="数据" />
      <el-table-column prop="operationDescribe" label="描述" />
      <el-table-column prop="createTime" label="操作时间" min-width="100px" align="center"/>
      <el-table-column
        fixed="right"
        label="操作"
        width="150px" align="center">
        <template slot-scope="scope">
<!--          <el-button type="text" size="small" @click="editHandle(scope.row.id)">编辑</el-button>-->
<!--          <el-divider direction="vertical"></el-divider>-->
          <template>
            <el-popconfirm
              title="这是一段内容确定删除吗？"
              @confirm="deleteFactory(scope.row)"
            >
              <el-button slot="reference" type="text">删除</el-button>
            </el-popconfirm>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      style="align-content: center; align-items: center; margin-left: 15px"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :total="totalCount"
      :page-size="PageSize"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
  </div>
  <!--  </div>-->
</template>

<script>
import {validatePhone} from "@/utils/validator";

export default {
  name: "AllType",
  data() {
    return {
      dialogFormVisible: false,
      updateForm : false,
      //添加表单的数据
      tableData: [],
      // 默认显示第几页
      currentPage:1,
      // 个数选择器（可修改）
      pageSizes:[1,2,3,4,5,6,7,8,9,10],
      // 总条数，根据接口获取数据长度(注意：这里不能为空)
      totalCount:1,
      // 个数选择器（可修改）
      PageSize:10,
      formLabelWidth: '120px',
      searchForm: {

      },
    };
  },

  mounted() {
    this.load();
  },

  methods : {
    deleteFactory(row) {
      this.axios.get('/sys/log/delete/' + row.id,).then(
        (resp) => {
          this.load()
        }
      )
    },
    // 分页
    // 每页显示的条数
    handleSizeChange(val) {
      // 改变每页显示的条数
      this.PageSize=val
      // 注意：在改变每页显示的条数时，要将页码显示到第一页
      this.currentPage=1
    },
    // 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      this.currentPage=val
    },

    load() {
      this.axios.post('/sys/log/select',this.searchForm).then((resp) => {
          this.tableData = resp.data;
          this.totalCount = resp.data.length
        }
      )
    }
  }
}
</script>

<style scoped>
.table {
  border-radius: 5px;
  margin: 10px;
  background-color: #FAFAFA;
  /*text-align: center;*/
}
.content {
  -webkit-box-shadow: #666 0px 0px 10px;
  -moz-box-shadow: #666 0px 0px 10px;
  box-shadow: #666 0px 0px 10px;
  background: #EEFF99;

  /*margin-right: 15px;*/
  /*margin-left: 15px;*/
}
.el-table {
  border-radius: 5px;
  margin-right: 15px;
  margin-left: 15px;
  margin-bottom: 10px;
  width: 98%;
}
</style>
